package com.hk.huakangcompany.mapper;

import com.hk.huakangcompany.model.ContactUs;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: zhe
 * @Date: 2021/6/15 11:33
 * @Statement: 联系我们Mapper层接口
 */
public interface ContactUsMapper extends BaseMapper<ContactUs> {

    /**
     * 1、在修改状态前，将所有状态修改为未启用 updateState1()
     * 2、将当前Id对应信息状态修改为启用 updateState(ContactUs contactUs);
     * @param contactUs
     * @return
     */
    @Update("update contact_us set state=#{state},gmt_modified=#{gmtModified} where id = #{id} ")
    int updateState(ContactUs contactUs);
    @Update("update contact_us set state = 1")
    int updateState1();

    @Override
    List<ContactUs> findAll(ContactUs contactUs);

    @Override
    int count(ContactUs contactUs);

    @Override
    ContactUs findById(Integer id);

    ContactUs findByState(@Param("state") int state);

    @Insert("insert into contact_us value " +
            "(null,#{site},#{phone},#{fax},#{email},#{url},#{state},#{gmtCreate},#{gmtModified})")
    @Override
    int save(ContactUs contactUs);

    @Update("update contact_us set " +
            "site=#{site},phone=#{phone},fax=#{fax},email=#{email},url=#{url},gmt_modified=#{gmtModified}" +
            "where id = #{id} ")
    @Override
    int update(ContactUs contactUs);

    @Delete("delete from contact_us where id = #{id} ")
    @Override
    int delete(Integer id);

}
